package com.glsc.ngateway.common.base.repo.mysql.flowable;

import com.glsc.ngateway.common.base.domain.mysql.flowable.FlowableDemand;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @author lium
 * @date 2022/2/7
 */
public interface FlowableDemandRepo extends JpaRepository<FlowableDemand, Long>, JpaSpecificationExecutor<FlowableDemand> {

    List<FlowableDemand> findByProcessInstanceId(String processInstanceId);

    List<FlowableDemand> findByRequestId(String requestId);

    List<FlowableDemand> findByProcessInstanceIdIn(List<String> processIds);

    @Query(value = "select * from t_flowable_demand m where 1=1 " +
            "and (:staff is null OR m.vc_staff= :staff) " +
            "and (:originalStaff is null OR m.vc_original_staff= :originalStaff) " +
            "and (:devUserId is null OR JSON_CONTAINS(vc_arrangeinfo,JSON_OBJECT('devUserId', :devUserId)) ) " +
            "and (COALESCE(:sameDepartmentAccounts) IS NULL OR (m.vc_staff IN (:sameDepartmentAccounts))) " +
            "and (:demandDetail is null or m.vc_demand_detail like CONCAT('%',:demandDetail,'%')) " , nativeQuery = true)
    List<FlowableDemand> findByVcStaffLikeOrVcOriginalStaffOrDevUserId(String staff, String originalStaff,String devUserId,List<String> sameDepartmentAccounts, String demandDetail);
}
